﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VAdvantage.Classes;
//using VAdvantage.Common;
//using System.Windows.Forms;
using VAdvantage.DataBase;
using VAdvantage.SqlExec;
using VAdvantage.Utility;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using VAdvantage.Logging;
using VAdvantage.Model;
using VAdvantage.Process;

namespace VAdvantage.Model
{
    public class MMasterForecast : X_C_MasterForecast
    {
        public MMasterForecast(Ctx ctx, int C_MasterForecast_ID, String trxName)
            : base(ctx, C_MasterForecast_ID, trxName)
        {


        }

        public MMasterForecast(Ctx ctx, DataRow dr, String trxName)
            : base(ctx, dr, trxName)
        {

        }

        protected override bool BeforeSave(bool newRecord)
        {
            try
            {
                if (newRecord)
                {
                    String sql = "select count(*) from c_masterforecast where processed = 'Y' and (currentversion = 'Y' or currentversion = 'N') and c_period_id = " + GetC_Period_ID();
                    int count = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                    if (count > 0)
                    {
                        ShowMessage.Info("SamePeriodExists", true, null, null);
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                // // MessageBox.Show("Error in MOrder--Before Save");
                return false;
            }
            return true;
        }

        protected override bool AfterSave(bool newRecord, bool success)
        {
            return base.AfterSave(newRecord, success);
        }

        protected override bool AfterDelete(bool success)
        {
            return base.AfterDelete(success);
        }
    }
}
